package com.lz.yz.home.web;

import com.github.pagehelper.PageHelper;
import com.lz.yz.base.entity.ReturnValue;
import com.lz.yz.home.entity.Banner;
import com.lz.yz.home.entity.Domain;
import com.lz.yz.home.service.BannerService;
import com.lz.yz.home.service.DomainService;
import com.lz.yz.reward.entity.Company;
import com.lz.yz.reward.service.CompanyService;
import com.util.common.Page;
import com.util.common.QueryList;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* Created by CodeGenerator on 2017/11/10.
*/
@RestController
@RequestMapping("/index")
public class HomeController {

    @Autowired
    BannerService bannerService;

    @Autowired
    DomainService domainService;

    @Autowired
    CompanyService companyService;

    @ApiOperation(value="banner列表",response = Banner.class)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "Authorization",value = "Bearer token",defaultValue = "Bearer "),
    })
    @GetMapping("/banners")
    public ReturnValue banners(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Banner> list = bannerService.findAll();
        QueryList<Banner> queryList = new QueryList(list, Page.toPage(list));
        return ReturnValue.generateTrueReturnValue(queryList);
    }

    @ApiOperation(value="领域分类列表",response = Domain.class)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "Authorization",value = "Bearer token",defaultValue = "Bearer "),
    })
    @GetMapping("/domains")
    public ReturnValue domains(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Domain> list = domainService.findAll();
        QueryList<Domain> queryList = new QueryList(list, Page.toPage(list));
        return ReturnValue.generateTrueReturnValue(queryList);
    }

    @ApiOperation(value="获取公司列表",response = Company.class)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "Authorization",value = "Bearer token",defaultValue = "Bearer "),
    })
    @GetMapping("/companys")
    public ReturnValue companys(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Company> list = companyService.findAll();
        QueryList<Company> queryList = new QueryList(list, Page.toPage(list));
        return ReturnValue.generateTrueReturnValue(queryList);
    }
}
